<?php

namespace App\Console;

use App\Console\Commands\BackUp;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

/***
 *  crontab -l 查看已存在的 Cron 条目
 *  crontab -e 来新增或编辑 Cron 条目  * * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1
 * 引入其它类时，在php.ini中，找到disable_functions选项，去掉proc_open 和 proc_get_status函数
 * 执行 php artisan schedule:run
 */
class Kernel extends ConsoleKernel
{
   /**
    * The Artisan commands provided by your application.
    *
    * @var array
    */
   protected $commands = [
      //加上新建任务的类名
      \App\Console\Commands\BackUp::class,
   ];

   /**
    * Define the application's command schedule.
    *
    * @param \Illuminate\Console\Scheduling\Schedule $schedule
    * @return void
    */
   protected function schedule(Schedule $schedule)
   {
//       $schedule->command('inspire')
//                ->hourly();
      //方法一
//      $schedule->call(function () {
//         file_put_contents('/home/www/test.log', date("Y-m-d H:i:s") . PHP_EOL, FILE_APPEND);
//      })->everyMinute();
      //方法二
//      $schedule->command('back:up')->everyMinute();
      //方法三
//      $schedule->command(BackUp::class)->everyMinute();
   }

   /**
    * Register the commands for the application.
    *
    * @return void
    */
   protected function commands()
   {
      $this->load(__DIR__ . '/Commands');

      require base_path('routes/console.php');
   }
}
